package org.dfg.corejava.jdk7;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * 异常相关
 * @author DingFugui
 */
public class TryCatchTest {
	public static void main(String[] args) {

	}

	// try-with-resources,自动关闭资源，只要其实现了AutoClose接口
	static String read() throws IOException {
		try (BufferedReader br = new BufferedReader(new FileReader(new File("")));) {
			return br.readLine();
		}
	}

	static void t1() throws FileNotFoundException, Exception {
		try {
			new BufferedReader(new FileReader(new File("")));
			Class.forName("");
		} catch (FileNotFoundException | ClassNotFoundException e) {
			// 多种异常同一处理机制
			e.printStackTrace();
			throw e;
		}
	}

	static void t2() throws FileNotFoundException, Exception {
		try {
			new BufferedReader(new FileReader(new File("")));
			Class.forName("");
		} catch (Exception e) {
			// 多种异常同一处理机制
			e.printStackTrace();
			throw e;// 把异常再向外抛时，只要方法声明了具体异常，编译器会自己确认异常类型
		}
	}
}
